home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-09-28 | 6.1 KB | 318 lines | [TEXT/KAHL] |
- //
- // This is sample code which will make QTVR object movies from Linear QuickTime movies.
- //
- // © 1991-1996 Apple Computer, Inc. All rights reserved.
- //
-
- #include "MakeQTVRObject.h"
- #include "extern.h"
-
-
- /***** DoEvent *****/
- void MainLoop()
- {
- char theChar,theChar2;
- RgnHandle theMouseRgn;
- EventRecord theEvent;
-
- theMouseRgn = NewRgn();
- while (gDone == false)
- {
- WaitNextEvent(everyEvent, &theEvent, nil, nil);
-
- if (!CheckMovieControllers(&theEvent))
- {
- switch (theEvent.what)
- {
- case kHighLevelEvent:
- AEProcessAppleEvent(&theEvent);
- break;
- case nullEvent:
- DoNull();
- break;
- case mouseDown:
- DoMouseDown(&theEvent);
- break;
- case keyDown:
- case autoKey:
- SetupMenus();
- theChar = theEvent.message & charCodeMask;
- theChar2 = (theEvent.message & keyCodeMask) >> 8;
- if (( theEvent.modifiers & cmdKey) != 0)
- DoMenuChoice( MenuKey( theChar));
- else
- KeyDown(theChar,theChar2);
- break;
- case updateEvt:
- DoUpdate(&theEvent);
- break;
- }
- }
-
- }
- DisposeRgn(theMouseRgn);
-
- }
-
- Boolean CheckMovieControllers(EventRecord *theEvent)
- {
- WindowPtr currWindow;
- MovieInstance *theInstance;
- GWorldPtr saveGW, movieGW;
- GDHandle saveGD, movieGD;
- ComponentResult eventHandled = false;
- Boolean isOS = false;
-
- GetGWorld(&saveGW, &saveGD);
-
-
- currWindow = FrontWindow();
- while(currWindow)
- {
- theInstance = GetMovieInstanceFromWindow(currWindow);
- if (theInstance)
- {
- GetMovieGWorld(theInstance->movie, &movieGW, &movieGD);
- SetGWorld(movieGW, movieGD);
- eventHandled = MCIsPlayerEvent( theInstance->movieController, theEvent);
- MoviesTask(theInstance->movie,1);
- SetGWorld(saveGW, saveGD);
- if (eventHandled != 0)
- return eventHandled;
- }
- currWindow = (WindowPtr)(((WindowRecord*)currWindow)->nextWindow);
- }
- SetGWorld(saveGW, saveGD);
-
- return false;
- }
-
- void DoUpdate(EventRecord *theEvent)
- {
-
- CWindowPtr whichWindow;
-
- whichWindow = (CWindowPtr)theEvent->message;
- SetGWorld(whichWindow,nil);
- BeginUpdate((WindowPtr)whichWindow);
-
- EndUpdate((WindowPtr)whichWindow);
- }
-
- /***** DoMouseDown *****/
- void DoMouseDown(EventRecord *theEvent)
- {
- WindowPtr whichWindow;
- short int thePart;
- long int menuChoice;
-
- thePart = FindWindow(theEvent->where, &whichWindow);
-
-
- switch (thePart)
- {
- case inMenuBar:
- SetupMenus();
- menuChoice = MenuSelect(theEvent->where);
- DoMenuChoice(menuChoice);
- break;
- case inSysWindow:
- SystemClick(theEvent, whichWindow);
- break;
- case inDrag:
- SelectWindow(whichWindow);
- SetGWorld((CWindowPtr)whichWindow,nil);
- DragWindow(whichWindow, theEvent->where, &qd.screenBits.bounds);
- break;
- case inGrow:
- break;
- case inZoomIn:
- case inZoomOut:
-
- break;
- case inGoAway:
- SelectWindow(whichWindow);
- SetGWorld((CWindowPtr)whichWindow,nil);
- CloseMovie(whichWindow);
- break;
- case inContent:
- if (whichWindow != FrontWindow())
- SelectWindow(whichWindow);
- break;
-
- }
- }
-
- void DoMenuChoice(long menuResult)
- {
- short menuID, menuItem, daRefNum;
- Str255 daName;
- MovieInstance *theInstance;
-
- theInstance = GetMovieInstanceFromWindow(FrontWindow());
- SetCursor(&qd.arrow);
-
- menuID = HiWord(menuResult); /* Use macros for efficiency to get */
- menuItem = LoWord(menuResult); /* menu item number and menu number. */
-
- switch (menuID) {
-
- case appleID:
- switch (menuItem) {
- case iAbout: /* Bring up alert for About. */
- About();
- break;
- default: /* All non-About items in this menu are DAs. */
- GetItem(GetMHandle(appleID), menuItem, daName);
- daRefNum = OpenDeskAcc(daName);
- break;
- }
- break;
-
- case fileID:
- switch (menuItem) {
- case iQuit:
- gDone = true;
- break;
- case iClose:
- CloseMovie(FrontWindow());
- break;
- case iOpen:
- {
- FSSpec theSpec;
- if(GetAMovie(&theSpec))
- OpenMovie(&theSpec);
- }
- break;
- case iDrop:
- gPrefInf.dropMode = !gPrefInf.dropMode;
- SavePrefs();
- break;
- case iSetPrefs:
- HandleMovieFormatDialog (theInstance,false);
- SavePrefs();
- break;
-
- }
- break;
-
- case editID:
- switch (menuItem) {
- case iMakeObject:
- {
- OSErr err;
-
- if(!theInstance) return;
- err = HandleMovieFormatDialog (theInstance,true);
- if(!err)
- {
- theInstance->isObjectMovie = true;
- SavePrefs();
- }
- }
- break;
- case iDeleteObject:
- {
- OSErr err;
- if(!theInstance ||
- !UserQuestion("\pAre you sure that you want to turn this object movie into a QuickTime movie?"))
- return;
- err = DeleteQTVRObjectFileFormat1x0 (
- theInstance->movie,
- theInstance->movieResFile,
- theInstance->movieResID,
- theInstance->spec);
-
- if(!err)
- {
- FSSpec tempSpec = theInstance->spec;
- CloseMovie (FrontWindow ());
- OpenMovie (&tempSpec);
- theInstance->isObjectMovie = false;
- }
- }
- break;
- case iSetPoster:
- DoSetStartUpView (theInstance);
- SavePrefs();
- break;
- case iShowPoster:
- ReopenMovie (theInstance);
- break;
- }
-
- }
-
- HiliteMenu(0); /* Unhighlight what MenuSelect (or MenuKey) hilited. */
- }
-
- /***** Show about Dialog *****/
- void About()
- {
- short itemHit;
- DialogPtr myDlg;
- Boolean done = false;
-
- myDlg = GetNewDialog( kAboutDLOG, 0, (WindowPtr) -1);
- SetDialogDefaultItem(myDlg,kDefaultOK);
-
- while ( !done)
- {
- ModalDialog( 0, &itemHit );
- switch ( itemHit )
- {
- case kDefaultOK:
- done = true;
- break;
- }
- }
- DisposDialog( myDlg);
-
- }
-
-
-
-
- void KeyDown(char theChar,char theChar2)
- {
-
- }
-
-
-
- void DoNull()
- {
- MyMoviesTask(FrontWindow());
- }
-
-
-
- void MyMoviesTask(WindowPtr theWindow)
- {
- MovieInstance *theInstance;
- Point pt;
- GWorldPtr saveGW, movieGW;
- GDHandle saveGD, movieGD;
-
- if(!theWindow)
- return;
-
- theInstance = GetMovieInstanceFromWindow(theWindow);
- if (!theInstance)
- return;
-
- GetGWorld(&saveGW, &saveGD);
- GetMovieGWorld(theInstance->movie, &movieGW, &movieGD);
- SetGWorld(movieGW, movieGD);
-
- GetMouse(&pt);
- if (!PtInMovie(theInstance->movie,pt))
- InitCursor();
- MoviesTask(theInstance->movie,1);
- SetGWorld(saveGW, saveGD);
- }
-
-
-
-
-